//
//  ChooseView.m
//  美食百科
//
//  Created by dllo on 16/1/26.
//  Copyright © 2016年 doll. All rights reserved.
//

#import "ChooseView.h"
#import "ClassModel.h"
@interface ChooseView()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,retain)UITableView *chooseTableView;
@end
@implementation ChooseView
- (void)dealloc
{
    [_chooseTableView release];
    [_nameArray release];
    [super dealloc];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
                self.chooseTableView = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
        self.chooseTableView.backgroundColor = [UIColor clearColor];
        self.chooseTableView.dataSource = self;
        self.chooseTableView.delegate = self;
        self.chooseTableView.scrollEnabled = NO;
       // self.chooseTableView.backgroundColor = [UIColor grayColor];
        [self addSubview:self.chooseTableView];
        [_chooseTableView release];
        [self.chooseTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"chooseView"];
    }
    return self;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.nameArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"chooseView"];
  ClassModel *class = self.nameArray[indexPath.row];
    cell.textLabel.text = class.name;
    cell.textLabel.lineBreakMode = NSLineBreakByTruncatingMiddle;
    cell.textLabel.textAlignment = NSTextAlignmentCenter;
    //cell.textLabel.textColor = self.color;
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return self.frame.size.height/self.nameArray.count;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{  ClassModel *classChoose = self.nameArray[indexPath.row];
    [self.delegate getLine:[classChoose.Id integerValue] rightName:classChoose.name];
    
    
    [UIView animateWithDuration:0.3 animations:^{
        self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y-self.frame.size.height, self.frame.size.width, self.frame.size.height);
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
